<?php
	class UserControl extends Control{

		function userReg(){
			
			$this->display("user/userreg.html");
		}

		function userLogin(){
			$this->display("user/userlogin.html");
		}

		//注册用户添加到数据库
		function userAdd(){
			if(isset($_GET['regname'])){
				$db = M("user");
				if($db->find('username="'.$_GET['regname'].'"')){
					echo 'er';die;
				}else{
					echo 'ok';die;
				}
			}
			if(isset($_POST['username'])){
				$db = M("user");
				$data = array();
				$data = $_POST;
				$data['password'] = md5($_POST['password']);			
				if($db->add($data)){
					echo json_encode(1);die;
				}else{
					echo json_encode(0);die;
				}
			}
		}


		function userLoginCheck(){
			if(isset($_POST['username'])){
				$username = $this->_post('username');
				$password = md5($this->_post('password'));

				$db = M("user");
				if($id = $db->find(array('username'=>$username,'password'=>$password))){
					$_SESSION['uid'] = $id['userid'];
					$_SESSION['username'] = $id['username'];
					echo 1;die;
				}else{
					echo 0;die;
				}
			}
		}

		function verify(){
			$code = new code();
			$code->show();
		}
	}
?>